home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
basic
/
vbtips.zip
/
VB-TIPS.TXT
Wrap
Text File
|
1991-08-04
|
33KB
|
1,078 lines
VB Tips
Compiled by Nelson Ford, 71355,470
For distribution on the MSLANG Forum only.
This is a compilation of information about VB that has flowed through the
Forum here (plus my own input). The hope is that new users can refer to this
file rather than having to ask the same questions on the forum all the time.
Experienced users whose memory is bad as mine might benefit from this as well.
Main contributors are:
Jonathan Zuck
Keith Funk
Mark Novisoff
Ted Young
Dennis Harrington
the Microsoft Section Leaders
Note: There are a number of very valuable free DLL's and VB routines on DL1
("New Uploads") and DL6 ("VB"). It is highly recommended that you Browse these
two DL's. A few are mentioned in this file, but many more are available.
Uploading: If you would like to share your coding with others, upload to DL1,
not DL6. All new uploads go to DL1 for 30 days and then are moved to the
appropriate DL (6, for VB). Do NOT put VBRUN100.DLL in your archive, nor any
of the other DLLs that are available on here. All that does is increase the
download time for everyone who already has those files. Instead, in your
upload description, just tell people that they need to download those files
too, if they don't already have them.
CONTENTS: [Names in brackets are files in the MSLANG DL's 1 or 6.]
General:
Button Colors
.EXE Size
Far Pointers
Help Files
Icon - Get Rid Of
Networks & VB
Saving Your Work
Screen type
Sound.DLL (Need TPW)
Type...End Type
Arrays:
Dynamic Arrays
[VBSORT]
Combo Boxes:
Changing Text
Color
Pseudo Combo Dropdown List Box
DOS Functions:
File Copying
[VBDOS]
Form & Control Placement, Sizing:
Controlling Form Size
"Floating" Window
Form Size and Granularity
Grouped Controls
Mouse Pointer, Position
Placing Forms, Controls
File I/O:
Btrieve
Deleting Data in Sequential File
MKI$ & CVI in VB
Fonts:
Using Different Fonts, Colors in a Box
System Font
Forms: (Also see "Form & Control Placement, Sizing", above)
Focus & Order of Execution
Focus on StartUp
SetFocus
Keyboard & Mouse:
Trapping Double-Click before Click
Using "Enter" in Place of "Tab"
List Boxes:
Finding an Item Added to a Sorted List Box
Inhibiting Screen Updating
Linking Sorted and Unsorted List Boxes
Searching For An Item
[VBSORT]
Picture Boxes:
Copying a Drawing to Clipboard
Drawing - Scale
Saving Picture Files
Printer:
Printer Setup
Printer Control Codes
Printing Forms
System:
Calling the Windows 3 Calculator
hWnd for a Control
.INI Files
Multi-Instance App Prevention
SendMessage
Windows Termination
Text Boxes:
Cursor (text), Position
Data Entry Masking
Data Entry Routine
Data Entry Text Limit
Flicker
Flashing Text
Timer
Using the Timer
Button Colors:
Button colors are controlled by WIN.INI. See the 6/11/91 issue of PC Mag
for details. Of course, changes you make there apply globally.
---------------
.EXE Size:
1. Long variable names increase EXE size.
2. Comments add a couple of bytes per line to EXE size.
3. A Global DIM of an array adds to EXE size.
For example:
Global sample as string*20000
will add about 20k to the size of the EXE file, but the same DIM
in a Form will not.
---------------
Far Pointers:
Here's a question regarding direct calls to the Windows API from a Visual Basic
procedure. In trying to set up a call to the API entry "Polygon", I discovered
that one of the arguments is a far pointer to an array of structures. I've
searched the VB documentation, but can't find a method that will return the
run-time address of a variable (or an array element) as a far pointer.
Is there a VB technique for passing a far pointer as an argument -- if so, how?
Also, how would such an argument be specified in the corresponding DECLARE
statement? Many thanks to anyone who can supply this information.
(Fm: Mark Novisoff (TA) 73047,3706)
If the structures themselves don't require pointers (which is the case with
Polygon), then it's a piece of cake. Use TYPE...END TYPE to declare a model
structure, and then DIM an array of the structures.
In your Global module Declare statement, use the "As" syntax:
Type Points
' Define the structure
X As Integer
Y As Integer
End Type
Declare Function Polygon Lib "Gdi" (hDC%, MyStruc As Points, nCount%)
In your code:
ReDim MyStrucArray(0 To 10) As Points
' Set the variables in the array here
Result = Polygon(hDC%, MyStrucArray(0), nCount%)
Note that this results in passing a far pointer to the zeroth element of the
array. Because the length of the structure is known to the DLL routine, it
will figure out where the rest of the elements are.
---------------
Help Files:
1. You can create Help files more easily and cheaply than with the SDK: use
the help compiler (HC.EXE) that comes with Turbo Pascal for Windows and
Borland C++.
2. A shareware program named Xantippe is a good front-end for making help
files.
---------------
Icon - Get Rid Of:
1. Click on the form
2. Select the Icon property from the properties bar.
3. Click on the middle portion of the properties bar, where (icon) shows.
4. Press the Del key
---------------
Networks & VB:
VBRUN100.DLL and VB apps (EXE's) should be placed on each machine's hard disk
to avoid significant performance degradation.
---------------
Saving Your Work:
Several users have reported losing their work in different ways. If you always
save before test-running your code, you can prevent most losses. If you get
any kind of warnings or other indications that something might be wrong with
your system, try to get into DOS (or use File Manager) and copy your project
files to a backup directory. Many people have had their project files
"trashed" when the system went screwy. There is a utility on the DLs here for
copying all the files in a Project - very handy to have, although a better
idea, generally, is to keep each project in its own subdirectory.
---------------
Screen type:
z = Screen.Height
If z = 6000 Then
Type$="CGA"
ElseIf z = 7000 Then
Type$ = "EGA"
ElseIf z > 7000 Then
Type$ = "VGA or Better"
End if
There's another way to do this, calling GetDeviceCaps to find out the vertical
resolution; but this method is a lot easier... BTW, if you want to know if it
is exactly VGA, not "or better" (i.e., better than 640x480), the number for
that 7200 if memory serves...
---------------
Sound.DLL (Need TPW):
Here's my DLL written in TPW. I had no documentation besides the Windows
Programmer's Reference so maybe someone here can tell me if I'm on the right
track. Some questions come to mind such as: how large shoule I make the voice
queue? Is it unecessary to open and close the sound device every time I want to
set a note?
library SoundDLL;
uses WinTypes, WinProcs;
procedure PlayNote(Note, nLength, Cdots: Integer);export; begin
OpenSound;
SetVoiceAccent(1,100,255,S_NORMAL,0);
SetVoiceQueueSize(1,1000);
SetVoiceNote(1,Note,nLength,Cdots);
StartSound;
WaitSoundState(S_QueueEmpty);
CloseSound;
StopSound; end;
exports PlayNote index 1;
begin end.
The declaration in VB (general):
Declare Sub PlayNote Lib "e:\tpw\output\soundll.dll" (ByVal note%, ByVal
Length%, ByVal Cdots%)
(Mark N.):
The size of the voice queue is one of those numbers that you simply "Pull
out of thin air". It depends on what you're going to do. For example, in
VBTools, we set the queue to 8K because we include several large pieces of
music.
OTOH, if you're going to play single notes on an occasional basis, then 1K
should be plenty.
It is not necessary to open and close the sound device every time. In fact,
if you close it while there are notes in the queue, they'll be lost!
I suggest that you do what we've done in VBTools:
1. Ope